package com.leo.base.initialize;

import com.leo.base.event.EventBusCenter;
import com.leo.base.event.annotation.EventBusListener;
import com.leo.base.util.SpringContextUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * @ClassName EventBusCenterInit
 * @Description
 * @Author wangss
 * @date 2020.09.20 20:58
 * @Version 1.0
 */
@Slf4j
@Component
public class EventBusCenterInit {

    @PostConstruct
    public void init() {
        // 获取所有带有 @EventBusListener 的 bean，将他们注册为监听者
        List<Object> listeners = SpringContextUtils.getBeansWithAnnotation(EventBusListener.class);
        for (Object listener : listeners) {
//            EventBusCenter.registerAsync(listener);
            EventBusCenter.registerSync(listener);
        }
    }
}
